package com.xingkong.app;

import java.io.InputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
/**
 * 使用FileSystem API来读取HDFS文件
 * 运行参数：hdfs://192.168.99.101:8020/user/input/README.txt
 * */
public class FileSystemCat {
	public static void main(String args[])throws Exception{
		String uri=args[0];
		Configuration conf=new Configuration();
		FileSystem fs=FileSystem.get(URI.create(uri), conf);
		InputStream in=null;
		try{
			in=fs.open(new Path(uri));
			IOUtils.copyBytes(in, System.out, 4096,false);
		}finally{
			IOUtils.closeStream(in);
		}
	}
}
